{extend name="layout" /}
{block name="content"}
<div class="row">
  <div class="col-xs-6">
    <form id="searchForm">
      <div class="seardiv" style="width: 20%;float: left;">
        <select name="roleid" class="form-control input-sm">
          <option value="">请选择用户类型</option>
          {volist name="$authgroup" id="v"}
          {if condition="$uinfo.userid == 1 || $v.id > $uinfo.roleid"}
          <option value="{$v.id}">{$v.title}</option>
          {/if}
          {/volist}
        </select>
      </div>
      <div class="seardiv" style="width: 20%;float: left;">
        <select name="isvip" class="form-control input-sm">
          <option value="">荣耀会员</option>
          <option value="1">是</option>
          <option value="0">否</option>
        </select>
      </div>
      <div class="seardiv" style="width: 20%;float: left;">
        <select name="dealerid" class="form-control input-sm">
          <option value="">请选择经销商</option>
          {volist name="deallist" id="v"}
          <option value="{$key}">{$v}</option>
          {/volist}
        </select>
      </div>
      <div class="input-group input-group-sm demoTable">
        <input type="text" class="form-control input-sm" name="keywords" id="demoReload" autocomplete="off"
          placeholder="请输入姓名或手机号">
        <span class="input-group-btn">
          <button type="button" class="btn btn-info btn-flat layui-btn" data-type="reload">搜 索</button>
        </span>
      </div>
    </form>
  </div>
  <div class="col-xs-6" style="text-align: right">
    <div class="seardiv" style="float: right;margin-left: 1%;">
      <input type="text" class="form-control input-sm date" style="width:100%;" name="end_time" placeholder="数据导出截止时间">
    </div>
    <div class="seardiv" style="float: right;margin-left: 1%;">
      <input type="text" class="form-control input-sm date" style="width:100%;" name="start_time"
        placeholder="数据导出起始时间">
    </div>
    <button type="button" class="btn btn-success btn-sm cocoModal" isForm url="{:url('add')}" title="新增项目" fixat="1"><i
        class="fa fa-plus"></i> 新增</button>
    <!-- {eq name="uinfo.roleid" value="6"} -->
    <!-- <button type="button" class="btn btn-success btn-sm cocoModal" isForm url="{:url('add_subord')}" title="新增项目" fixat="1"><i class="fa fa-plus"></i> 添加经纪人</button> -->
    <!-- {/eq} -->
    <button type="button" class="btn btn-info btn-sm export" title="用户表" user-excel="1"><i class="fa fa-edit"></i>
      数据导出</button>
  </div>
</div>
<table class="layui-table"
  lay-data="{height: 'full-75', cellMinWidth: 80, page: true,id: 'lists',limit:30, url:'{:url('data_show_where',['order'=>'desc'])}'}"
  lay-filter="lists">
  <thead>
    <tr>
      <th lay-data="{type:'checkbox'}">ID</th>
      <th lay-data="{field:'userid', sort: true}">UID</th>
      <th lay-data="{field:'username'}">用户名</th>
      <th lay-data="{field:'realname'}">姓名</th>
      <th lay-data="{field:'phone'}">手机号</th>
      <!-- <th lay-data="{field:'email'}">邮箱</th> -->
      <!-- <th lay-data="{field:'jifen'}">积分数量</th> -->
      <th lay-data="{field:'rolename'}">用户类型</th>
      <th lay-data="{field:'isvip'}">荣耀会员</th>
      <th lay-data="{field:'dealer'}">所属经销商</th>
      <th lay-data="{field:'lastloginip'}">登录IP</th>
      <th lay-data="{field:'lastlogintime'}">登录时间</th>
      <th lay-data="{field:'register_code'}">注册码</th>
      <th lay-data="{field:'addtime'}">注册时间</th>
      <th lay-data="{field:'statusname'}">状态</th>
      <th lay-data="{fixed: 'right', width:180, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  {{# if(d.roleid == 9 && d.vip == 1){ }}
  <a class="layui-btn layui-btn-xs" lay-event="appendcoupons">补发优惠券</a>
  {{# } }}
  <!-- <a class="layui-btn layui-btn-xs" lay-event="auth_manage">权限管理</a> -->
  {{# if(d.roleid == 5 || d.roleid == 7){ }}
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  {{# } }}
  {{# if((d.roleid == 8 || d.roleid == 10 || d.roleid == 11) && d.openid != ""){ }}
   <a class="layui-btn layui-btn-xs" lay-event="mp_qrimage">小程序码</a>
   {{# } }}
</script>
{/block}
{block name="script"}
<script type="text/javascript">
  function appendcoupons(data) {
    console.dir(data);
    var layindex = layer.open({
      type: 2,
      area: ['800px', '600px'],
      fixed: false, //不固定
      maxmin: true,
      content: APP_URL + "/admin/adminuser/append_coupons?userid=" + data.id,
      title: '选择要补发的优惠券',
      btn: ['确定', '取消'],
      shade: [0.8, '#000000'],
      yes: function (index, layero) {
        //parent.$('#parentIframe').text('我被改变了');
        var iframeWin = window[layero.find('iframe')[0]['name']];
        formobj = iframeWin.$("form");
        ajaxUrl = formobj.attr("action");
        if (ajaxUrl == undefined || ajaxUrl == '') {
          ajaxUrl = defaultSaveUrl;
        }
        datajson = formobj.serialize();
        searchMap.postData = datajson;
        $.post(ajaxUrl, searchMap, function (datajson) {
          var serializeObj = {};
          if (datajson.status == 1) {
            $(formobj.serializeArray()).each(function () {
              serializeObj[this.name] = this.value;
            });
            layer.msg("操作成功", function () {
              layer.closeAll();
            });
            setTimeout(function () {
              location.reload();
            }, 300);
          }
          else {
            layer.msg(datajson.msg);
            return false;
          }
        }, 'json');
      }
    });
  }
</script>
<script type="text/javascript">
  layui.use('table', function () {
    var table = layui.table;
    var $ = layui.$, active = {
      reload: function () {
        var demoReload = $('#demoReload');
        //执行重载
        table.reload('lists', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          , where: $('#searchForm').serializeObject()
        });
      }
    };
    $('.demoTable .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
</script>
<script type="text/javascript">
  function auth_manage(data) {
    var layindex = layer.open({
      type: 2,
      area: ['500px', '400px'],
      fixed: false, //不固定
      maxmin: true,
      content: APP_URL + "/admin/adminuser/user_auth?items=" + data.id,
      title: '权限管理',
      shade: [0.8, '#000000']
    });
  }
  function mp_qrimage(data) {
    var layindex = layer.open({
      type: 2,
      area: ['500px', '500px'],
      fixed: false, //不固定
      maxmin: true,
      content: APP_URL + "/admin/adminuser/image?id=" + data.id,
      title: '小程序码',
      shade: [0.8, '#000000']
    });
  }
</script>
{/block}